package com.wingsofts.custombehavior;

import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by wing on 16/8/23.
 */
public class EasyBehavior2 extends CoordinatorLayout.Behavior<TextView> {//这里的泛型是child的类型，也就是观察者View


  public EasyBehavior2(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
    return dependency instanceof Button;
  }

  @Override
  public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
    child.setX(dependency.getX()+100);
    child.setY(dependency.getY()+200);
    child.setText("我跟button一起动");
    return true;
  }

  @Override
  public void onDependentViewRemoved(CoordinatorLayout parent, TextView child, View dependency) {
    super.onDependentViewRemoved(parent, child, dependency);
  }
}
